/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.bicycle.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.bicycle.entity.BicycleUser;
import com.jeesite.modules.bicycle.service.BicycleUserService;

/**
 * BlueBike用户Controller
 * @author 谢宇燊
 * @version 2020-04-07
 */
@Controller
@RequestMapping(value = "${adminPath}/bicycle/bicycleUser")
public class BicycleUserController extends BaseController {

	@Autowired
	private BicycleUserService bicycleUserService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public BicycleUser get(String id, boolean isNewRecord) {
		return bicycleUserService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("bicycle:bicycleUser:view")
	@RequestMapping(value = {"list", ""})
	public String list(BicycleUser bicycleUser, Model model) {
		model.addAttribute("bicycleUser", bicycleUser);
		return "modules/bicycle/bicycleUserList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("bicycle:bicycleUser:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<BicycleUser> listData(BicycleUser bicycleUser, HttpServletRequest request, HttpServletResponse response) {
		bicycleUser.setPage(new Page<>(request, response));
		Page<BicycleUser> page = bicycleUserService.findPage(bicycleUser);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("bicycle:bicycleUser:view")
	@RequestMapping(value = "form")
	public String form(BicycleUser bicycleUser, Model model) {
		model.addAttribute("bicycleUser", bicycleUser);
		return "modules/bicycle/bicycleUserForm";
	}

	/**
	 * 保存BlueBike用户
	 */
	@RequiresPermissions("bicycle:bicycleUser:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated BicycleUser bicycleUser) {
		bicycleUserService.save(bicycleUser);
		return renderResult(Global.TRUE, text("保存BlueBike用户成功！"));
	}
	
	/**
	 * 删除BlueBike用户
	 */
	@RequiresPermissions("bicycle:bicycleUser:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(BicycleUser bicycleUser) {
		bicycleUserService.delete(bicycleUser);
		return renderResult(Global.TRUE, text("删除BlueBike用户成功！"));
	}
	
}